package com.jzl.canal_consumer.bean;

import com.alibaba.otter.canal.protocol.CanalEntry;

import java.util.ArrayList;
import java.util.List;

/**
 * 非线程安全
 *
 * @author ZhenWuWang
 */
public class TableBatchMergeSqlEntry
{
    private final String tableName;

    private final List<MergeSqlEntry> mergeSqlEntries;

    private final List<CanalEntry.Entry> transactionEntries;

    public TableBatchMergeSqlEntry(String tableName)
    {
        this.tableName = tableName;
        this.mergeSqlEntries = new ArrayList<>();
        this.transactionEntries = new ArrayList<>();
    }

    public String getTableName()
    {
        return tableName;
    }

    public void addMergeSqlEntry(MergeSqlEntry mergeSqlEntry)
    {
        mergeSqlEntries.add(mergeSqlEntry);
    }

    public void addMergeSqlEntries(List<MergeSqlEntry> mergeSqlEntries)
    {
        if (mergeSqlEntries != null && mergeSqlEntries.size() > 0)
        {
            this.mergeSqlEntries.addAll(mergeSqlEntries);
        }
    }

    public void addTransactionEntries(CanalEntry.Entry entry)
    {
        transactionEntries.add(entry);
    }

    public void addTransactionEntries(List<CanalEntry.Entry> entries)
    {
        if (entries != null && entries.size() > 0)
        {
            transactionEntries.addAll(entries);
        }
    }

    public MergeSqlEntry getLastMergeSqlEntry()
    {
        if (mergeSqlEntries.isEmpty())
        {
            return null;
        }
        return mergeSqlEntries.get(mergeSqlEntries.size() - 1);
    }

    public List<MergeSqlEntry> getMergeSqlEntries()
    {
        return mergeSqlEntries;
    }

    public List<CanalEntry.Entry> getTransactionEntries()
    {
        return transactionEntries;
    }
}
